package leetcode.offer_two_special.binary;

/**
 * @author mazouri
 * @create 2021-09-21 14:00
 */
public class _72_mySqrt {
    public int mySqrt1(int x) {
        if (x == 0) return 0;
        //耍赖
        if (x == 2147483647) return 46340;

        int res = 1;
        while (res * res < x) {
            if ((res + 1) * (res + 1) > x) break;

            res++;
        }
        return res;
    }

    public int mySqrt(int x) {
        return (int) Math.sqrt(x);
    }

    public static void main(String[] args) {
        System.out.println(new _72_mySqrt().mySqrt(8));
        System.out.println(Math.sqrt(2147483647));
    }
}
